package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.UploadUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author by mycp
 * @Classname StrategyCatalogController
 * @Description TODO 大攻略处理器
 * @Date 2018/11/7 22:05
 */
@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyCatalogQueryObject qo, Model model) {
        PageInfo pageInfo = strategyCatalogService.query(qo);
        model.addAttribute("pageInfo", pageInfo);

        // 查询所有不被禁用的攻略
        model.addAttribute("strategies", strategyService.selectEnable());
        return "strategyCatalog/list";
    }


    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(StrategyCatalog strategyCatalog, MultipartFile img) {
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return "redirect:/strategyCatalog/list.do";
    }


    /**
     * 获取指定大攻略 id 的所有不被禁用的攻略类别
     * @param strategyId
     * @return
     */
    @RequestMapping("/getCatalogsByStrategyId")
    @ResponseBody
    public Object getCatalogsByStrategyId(Long strategyId){
        List<StrategyCatalog> list = strategyCatalogService
                .selectEnable(strategyId);
        return list;
    }
}
